package com.szh.mysobproject.ui.adapter

import android.annotation.SuppressLint
import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.annotation.DrawableRes
import androidx.lifecycle.MutableLiveData
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.szh.mysobproject.R
import com.szh.mysobproject.databinding.VipIntroItemBinding

/**
 * @author : create by  szh
 * @date : 2022/7/6 11:16
 * @desc :Vip特权介绍适配器
 */

class VipIntroAdapter : RecyclerView.Adapter<VipIntroAdapter.ViewHolder>() {

    private val mData: MutableList<VipIntro> = arrayListOf()

    @SuppressLint("NotifyDataSetChanged")
    fun setData(data: List<VipIntro>) {
        mData.clear()
        mData.addAll(data)
        notifyDataSetChanged()
    }

    inner class ViewHolder(val context: Context, val binding: VipIntroItemBinding) :
        RecyclerView.ViewHolder(binding.root) {
        fun onBinding(item: VipIntro, position: Int) {
            val ivIcon = binding.ivIcon
            Glide.with(context)
                .load(item.resId)
                .into(ivIcon)
            binding.tvTitle.text = item.title
            binding.tvDesc.text = item.desc
        }
    }

    data class VipIntro(@DrawableRes val resId: Int, val title: String, val desc: String)

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val inflater = LayoutInflater.from(parent.context)
        val bind = VipIntroItemBinding.inflate(inflater, parent, false)
        return ViewHolder(parent.context, bind)
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val item = mData[position]
        holder.onBinding(item, position)
    }

    override fun getItemCount(): Int = mData.size
}